<template>
  <div style="padding-left:10px; padding-right: 10px; width: calc(100vw - 200px)">
    <!--    搜索区域-->
    <div style="margin: 10px 0">
      <span style="color: #611ee3;font-size: large;">课程名：</span>
      <el-input v-model="search" placeholder="请输入课程名" style="width: 20%" clearable></el-input>
      <el-button style="margin-left: 5px; background-color: #409EFF; color: white" @click="load" plain>查询</el-button>
    </div>
    <el-table
        :data="tableData"
        border
        stripe
        style="width: 100%">
      <el-table-column
          prop="id"
          label="ID"
          sortable>
      </el-table-column>
      <el-table-column
          prop="courseName"
          label="课程名">
      </el-table-column>
      <el-table-column
          prop="coachName"
          label="教练名">
      </el-table-column>
      <el-table-column
          label="课程封面">
        <template #default="scope">
          <div class="demo-image__preview">
            <el-image
                style="width: 100px; height: 100px"
                :src="scope.row.courseImg"
                :preview-src-list="[scope.row.courseImg]">
            </el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column
          prop="courseInfo"
          label="课程信息">
      </el-table-column>
      <el-table-column
          prop="coursePrice"
          label="单价">
      </el-table-column>
      <!--      <el-table-column-->
      <!--          prop="courseStaus"-->
      <!--          label="发布时间">-->
      <!--      </el-table-column>-->
      <el-table-column
          label="课程状态">
        <template #default="scope">
          <span v-if="scope.row.courseStatus==='1'">未开始</span>
          <span v-if="scope.row.courseStatus==='2'">进行中</span>
          <span v-if="scope.row.courseStatus==='3'">已结束</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="startDate"
          label="开始时间">
      </el-table-column>
      <el-table-column
          prop="endDate"
          label="结束时间">
      </el-table-column>
    </el-table>
<!--    <div style="margin: 10px 0">-->
<!--      <el-pagination-->
<!--          background-->
<!--          @size-change="handleSizeChange"-->
<!--          @current-change="handleCurrentChange"-->
<!--          :current-page="currentPage4"-->
<!--          :page-sizes="[5, 10, 20]"-->
<!--          :page-size="pageSize"-->
<!--          layout="total, sizes, prev, pager, next, jumper"-->
<!--          :total="total">-->
<!--      </el-pagination>-->
<!--    </div>-->
  </div>
</template>

<script>


import request from "@/utils/request";

export default {
  name: 'course',
  components: {

  },
  data() {
    return {
      member: {},
      search:'',
      currentPage4: 1,
      pageSize: 10,
      total:0,
      dialogVisible:false,
      tableData: [],
      user:{},
      deleteVisible: false
    }
  },
  created() {
    let Str =sessionStorage.getItem("member") || '{}';
    this.member = JSON.parse(Str);
    this.load();
    let userStr =sessionStorage.getItem("user") || '{}';
    this.user = JSON.parse(userStr);
//请求后端服务器，确认当前登录用户的合法性
    request.get("/api/user/"+this.user.id).then(res=>{
      if (res.code==='0'){
        this.user = res.data;
      }
    });
  },
  methods:{
    load(){
      request.get("/api/consumRecord/getConsumRecord",{
        params: {
          memberId: this.member.id,
          search:this.search
        }
      }).then(res =>{
        console.log(res);
        this.tableData = res.data;
        // this.total = res.data.total;
      })
    },
    handleSizeChange(pageSize){//改变当前页面个数
      this.pageSize = pageSize;
      this.load();
    },
    handleCurrentChange(pageNum){//改变当前页码
      this.currentPage4 = pageNum;
      this.load();
    }
  }
}
</script>
